package com.qmyx.supply.admin.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.request.OrderProblemListRequest;
import com.ytjj.qmyx.supplychain.common.model.request.OrderProblemReplyRequest;
import com.ytjj.qmyx.supplychain.common.model.response.OrderProblemListResponse;
import com.ytjj.qmyx.supplychain.mapper.entity.YxBanker;
import com.ytjj.qmyx.supplychain.service.BankerService;
import com.ytjj.qmyx.supplychain.service.OrderProblemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/orderProblem")
public class OrderProblemController {

    @Resource
    private OrderProblemService orderProblemService;
    @Resource
    private BankerService bankerService;

    /**
     * 回复订单问题
     * @param request
     * @return
     */
    @PostMapping("/replyProblem")
    public CommonResult commitProblem(@RequestBody OrderProblemReplyRequest request) {
        YxBanker userInfo = bankerService.getUserInfo();
        request.setCommitUserName(userInfo.getName());
        request.setReplyRole(3);
        return CommonResult.success(orderProblemService.replyProblem(request));
    }

    /**
     * 订单问题列表
     * @param request
     * @return
     */
    @PostMapping("/orderProblemList")
    public CommonResult<CommonPage<OrderProblemListResponse>> orderProblemList(@RequestBody OrderProblemListRequest request) {
        YxBanker userInfo = bankerService.getUserInfo();
        request.setBankerId(userInfo.getId());
        request.setQueryType(3);
        return CommonResult.success(orderProblemService.orderProblemList(request));
    }

    /**
     * 订单问题详情
     * @param id
     * @return
     */
    @GetMapping("/orderProblemDetail")
    public CommonResult orderProblemDetail(@RequestParam Integer id) {
        return CommonResult.success(orderProblemService.orderProblemDetail(id));
    }

    /**
     * 修改供应商处理状态
     */
    @GetMapping("/updateProblemBankerDealStatus")
    public CommonResult updateProblemBankerDealStatus(@RequestParam(value = "id") Integer id,
                                            @RequestParam(value = "bankerDealStatus") Integer bankerDealStatus) {
        return CommonResult.success(orderProblemService.updateProblemBankerDealStatus(id,bankerDealStatus));
    }
}
